<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<%@ taglib prefix ="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<%@ include file="/common/common-css.jsp" %>
		<style>
		#jquery-table201 td{word-wrap: break-word;word-break: break-word;}
		.load_bg{background:#000;opacity:0.1;left:0px;top:0px;position:fixed;height:100%;width:100%;overflow:hidden;z-index:10000;}
		.load_img{left:50%;top:180px;position:fixed;height:50px;overflow:hidden;z-index:20000;}
		.item-name{
			border: none !important;
		    background: none !important;
		    outline: none !important;
		    line-height: 1 !important;
		    width: 100% !important;
		    text-align: center !important;
		}
		</style>
	</head>
<body  class="no-skin">
<div  class="load_bg" style="display:none;" ></div>
<img src="http://img.xmiles.cn/commentloading.gif" class="load_img" style="display:none"/>
<div class="page-content">
<div id="test"></div>
			<div class="page-header" style="margin-bottom:0px;padding-bottom:10px;">
			
				<h1 id="fu_name">
					
				</h1>
			</div>
	<form id="queryForm" >
	<div class="page-content-area">
		<div class="row">
			<div class="col-sm-12">
				<div class="widget-box" style="border:0px solid #ccc; border-top:none;border-bottom:none;">
					<div class="widget-header widget-header-blue widget-header-flat">
						<h4 class="widget-title">选择条件进行查询</h4>

						<div class="widget-toolbar">
							<a href="#" data-action="collapse">
								<i class="ace-icon fa fa-chevron-up"></i>
							</a>
						</div>
					</div>

					<div class=" widget-body">
						<!-- <div class="widget-main" style="padding:12px;border:0px solid #ccc; border-top:none;border-bottom:none;"> -->
						<div class="widget-main" >
										<div class="form-group col-xs-12 col-sm-2">
											<label class="col-sm-4 control-label"  style="text-align:right"  for="sex">时间:</label>
											<div class="col-sm-8">
												<div class="input-daterange input-group col-sm-12">
													<input type="text" data-date-format="yyyy-mm-dd" class="fromDate date-picker input-sm form-control" style="padding-left:0px" name="day">
												</div>
											</div>
										</div>
										<div class="form-group col-xs-12 col-sm-6">
											<label class="col-sm-2 control-label"  style="text-align:right"  for="url">网址:</label>
											<div class="col-sm-10">
												<div class="input-daterange input-group col-sm-12">
													<input type="text" name="url" class="form-control text-left">
												</div>
											</div>
										</div>
										<div class="form-group col-xs-12 col-sm-4">
											<label class="col-sm-2 control-label"  style="text-align:right"  for="status">状态：</label>
											<div class="col-sm-8">
												<div class="input-daterange input-group col-sm-12">
													<select class="col-sm-6" name="status" id="status">
													  <option value="">-请选择-</option>
													  <option value="200">-200-</option>
													  <option value="206">-206-</option>
													  <option value="302">-302-</option>
													  <option value="304">-304-</option>
													  <option value="400">-400-</option>
													  <option value="403">-403-</option>
													  <option value="404">-404-</option>
													  <option value="405">-405-</option>
													  <option value="499">-499-</option>
													  <option value="500">-500-</option>
													  <option value="505">-505-</option>     
													</select>
												</div>
											</div>
										</div>
							</div><!-- /.widget-main -->
					</div><!-- /.widget-body -->
				</div><!-- /.widget-box -->
			</div><!-- /.col-sm-12 -->
				<div class="col-md-12 center">
				<div class="clearfix form-actions">
				
					<button class="btn btn-purple  no-border" type="button" name="btn-query" onclick="query_any()" id="btn-query">
						<i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
						查询
					</button>
					&nbsp;&nbsp;&nbsp;
					<button class="btn btn-grey  no-border" type="reset">
						<i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
						重置
					</button>
					
				  </div>
		   </div>
		</div><!-- /.row --> 
		
		<div class="row">
			<div class="col-xs-12">
				<table id="jquery-table201" class="table table-striped table-bordered table-hover">			
				</table>
			</div>
		</div>
	</div><!-- /.page-content-area -->
	
	</form>
</div><!-- /.page-content -->

<%@ include file="/common/common-js.jsp" %>
<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
<script type="text/javascript" src="${ctx}/statistics/homepage/comm.js"></script>
<!-- inline scripts related to this page -->
<script type="text/javascript">
var requesturl = "http://xmiles.cn/stat_service/common";
//var requesturl = "http://localhost:8080/stat_service/common";
var platform = '';
 //【查询】按钮Click事件
	  function query_any(){
	  
  		platform = $('#platform').val();
	  	var statisticstype = $('#statisticstype').val();
	  	
	    	loaddata(statisticstype);
			$("#checkAll").on("change", function () {
				if($("#checkAll").prop("checked")==true){
					$('input[name = "id"]:checkbox').prop("checked", true);
				}
				else{
					$('input[name = "id"]:checkbox').prop("checked", false);
				}	
		});
	    	
	  }
	  
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
 	var r = window.location.search.substr(1).match(reg);
	if (r != null) return decodeURI(r[2]); return null;
	
};
function trim(str){ //删除左右两端的空格
　　return str.replace(/(^\s*)|(\s*$)/g, "");
};
	 

window.onload=function(){
	  var searchType = getQueryString("searchType");
	  var interface_id = getQueryString("interface_id");
	  var fullTime = CurentTime();
    $('.fromDate').val(fullTime);
 	 loaddata(searchType,interface_id);
};

var jqTable201 = null;

function CurentTime(){ 
        var   today=new   Date();      
        var   yesterday_milliseconds=today.getTime()-1000*60*60*24;    
   
        var   yesterday=new   Date();      
        yesterday.setTime(yesterday_milliseconds);      
            
        var strYear=yesterday.getFullYear(); 
   
        var strDay=yesterday.getDate();   
        var strMonth=yesterday.getMonth()+1; 
   
        if(strMonth<10)   
        {   
            strMonth="0"+strMonth;   
        }  
        if(strDay<10)   
        {   
            strDay="0" + strDay;   
        } 
        var strYesterday=strYear+"-"+strMonth+"-"+strDay;   
   		 return(strYesterday); 
} 


var loaddata = function(searchType,interface_id){
   $('.load_bg,.load_img').show();
	jQuery(function($) {
	  $('.dataTables_wrapper').css('display', 'none');
      //详情统计
      if (jqTable201 != null) {
  	  $('#jquery-table201_wrapper').css('display','block');
  	  jqTable201.fnDraw();
  	  		return;
  	  		}
        	jqTable201 = $('#jquery-table201').dataTable( {
        		"columnDefs": [
  		    	
  		    	{
  		    		  "title":"请求时间",
  		    		  "name":"time",
  		    		  "data": "time",
  		    	  	  "targets": [0], 
  		    	  	  "bSortable": false,
					  "class": "center",
   		    	  	  "width": "300px"
  		    	},
  		    	{
  		    		  "title":"请求链接",
  		    		  "name":"request_url",
  		    		  "data": "request_url",
  		    	  	  "targets": [1], 
  		    	  	  "bSortable": false,
					  "class": "left"
  		    	},
  		    	{
  		    		  "title":"消息体大小",
  		    		  "name":"body_bytes_sent",
  		    		  "data": "body_bytes_sent",
  		    	  	  "targets": [2], 
  		    	  	  "bSortable": true,
					  "class": "center",
   		    	  	  "width": "300px"
  		    	},
  		    	{
  		    	 	  "title":"消息大小",
  		    	 	  "name":"bytes_sent",
  		    	 	  "data": "bytes_sent",
  		    	  	  "targets": [3],
  		    	 	  "bSortable": true,
					  "class": "center",
   		    	 	  "width": "300px",
  		    	},
  		    	{
		    	 	  "title":"响应时间",
		    	 	  "name":"upstream_response_time",
		    	 	  "data": "upstream_response_time",
		    	  	  "targets": [4],
		    	 	  "bSortable": true,
					  "class": "center",
 		    	 	  "width": "300px",
		    	},
  		    	{
		    	 	  "title":"请求时间",
		    	 	  "name":"request_time",
		    	 	  "data": "request_time",
		    	  	  "targets": [5],
		    	 	  "bSortable": true,
					  "class": "center",
 		    	 	  "width": "300px",
		    	},
  		    	{
		    	 	  "title":"次数",
		    	 	  "name":"count",
		    	 	  "data": "count",
		    	  	  "targets": [6],
		    	 	  "bSortable": true,
					  "class": "center",
 		    	 	  "width": "300px",
		    	},
  		    	{
		    	 	  "title":"状态码",
		    	 	  "name":"status",
		    	 	  "data": "status",
		    	  	  "targets": [7],
		    	 	  "bSortable": false,
					  "class": "center",
 		    	 	  "width": "300px",
		    	}
  		    	 
  		  	],
  			"sAjaxSource": requesturl,
  			"fnServerData": function ( sSource, aoData, fnCallback ) {//从服务器请求数据
  		   			var data = $('#queryForm').serializeObject();
  		   			aoData = JSON.stringify(aoData).replace(new RegExp("\/\/","gm"),"");
  		   			aoData = JSON.parse(aoData);
  		   			data.aoData = aoData;
  					var test =  JSON.stringify(data);
  					test = test.slice(1,test.length);
  					var databean;
  					$.ajax({
  						"type": "POST",
  						"dataType": 'json',
  						"url": sSource,
  						"data": '{"data":{"databean":{"interface_id":"'+ interface_id +'","type":"'+ searchType + '",' + test +'},"shandle":"0","handle":"0"}',
  						"success": function(resp){
  						   console.log(resp);
  							fnCallback(resp);
  							initListPage();
  							
  						},		
  						"error": function(XMLHttpRequest, textStatus, errorThrown) {
  						
  						},
  						"complete":function(){
							$(".load_bg,.load_img").hide();
						}
  										
  				  });
                    $.ajaxSetup({ 
                        xhrFields: { withCredentials: false }, 
                        crossDomain: true 
                    });
  			},
  			"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
  				nRow.ondblclick = function() {               
  					var urlValue = trim(nRow.childNodes[1].innerHTML);
  					urlValue = urlValue.replace(new RegExp("&amp;","gm"),"andTran");
  					urlValue = urlValue.replace(new RegExp("\"","gm"),"");
  					var inter_id = 409;
					var url = '/statistics/nginxRequest-inside.jsp?interface_id=' + inter_id + '&json={"url":"'+ urlValue +'"}';
					openDialogWithRand(url,1200,780,"查看统计详情",function (data){});
				};
  			},
  			"sScrollXInner": "100%",
  			"bRetrieve": true,
  			"sScrollY": "100%",//如果不设置，IE会有问题
  		    "aaSorting": [[4,"desc"]] 
        	});
	});
}
	
	jQuery(function(){
		
		//省份联动城市的变动
	    $("#province").bind("change", function () { 
			var select_province = $(this).val();
	    	var citys = $("#cityid");
	    	citys.empty();
	        $.getJSON(ctx + "/life/region/getCityByProvinceid.action", {provinceid : select_province}, function (returnObj) {
	           for (var i=0;i<returnObj.citys.length; i++) {
	        	   	var city = returnObj.citys[i];
	        	   	citys.append("<option value='" + city.id + "'>" + city.name + "</option>");
	    	   }
	        });
		});
		
		//省份联动城市的变动
	    $("#carProvince").bind("change", function () { 
			var select_province = $(this).val();
	    	var citys = $("#carCity");
	    	citys.empty();
	        $.getJSON(ctx + "/life/region/getCityByProvinceid.action", {provinceid : select_province}, function (returnObj) {
	           for (var i=0;i<returnObj.citys.length; i++) {
	        	   	var city = returnObj.citys[i];
	        	   	citys.append("<option value='" + city.id + "'>" + city.name + "</option>");
	    	   }
	        });
		});
		
		var itemName = '';
		
		$(document).delegate('.item-name', 'focus', function(){
			itemName = $(this).val();
		});
		
		$(document).delegate('.item-name', 'blur', function(){
			var prd_id = $(this).attr('data-prd_id');
			var name = $(this).val();
			if(itemName != name){
				$.ajax({
					"type": "POST",
					"dataType": 'json',
					"url": "http://xmiles.cn/stat_service/common",
					"data": '{"data":{"databean":{"interface_id":"406","prd_id":"' + prd_id + '", "prd_name":"' + name + '"}},"shandle":"0","handle":"0"}',
					"beforeSend":function(){
						$(".load_bg,.load_img").show();
					},
					"success": function(resp){
					   console.log(resp);
					},		
					"error": function(XMLHttpRequest, textStatus, errorThrown) {
						console.log(XMLHttpRequest, textStatus, errorThrown);
					    alert(textStatus);
					},
					"complete":function(){
						$(".load_bg,.load_img").hide();
					}
									
			    });
			}
		});
	
	});
	
</script>
		
</body>
</html>
